from enum import Enum
from typing import Optional
from pydantic import BaseModel, Field


class ClientOption(str, Enum):
    MQTT = "MQTT"
    HTTP = "HTTP"
    WebSocket = "WebSocket"


class MqttClientInSchema(BaseModel):
    clientId: Optional[str] = Field(default=None, title="mqtt客户端唯一id")
    name: str = Field(title="客户端名称")
    comType: str = Field(title="连接类型，可选项：mqtt mqtts ws wss")
    host: str = Field(title="mqtt服务器地址")
    port: int = Field(title="mqtt服务器端口号") 
    username: Optional[str] = Field(default=None, title="客户端登录用户名")
    password: Optional[str] = Field(default=None, title="客户端登录密码")
    willTopic: Optional[str] = Field(default=None, title="遗嘱话题名称")
    willPayload: Optional[str] = Field(default=None, title="遗嘱内容")
    willQoS: Optional[int] = Field(default=None, title="遗嘱话题质量")
    willRetain: Optional[bool] = Field(default=False, title="遗嘱话题持久化")


class MqttClientUpdateSchema(MqttClientInSchema):
    name: Optional[str] = Field(default=None, title="客户端名称")
    host: Optional[str] = Field(default=None, title="mqtt服务器地址")
    port: Optional[int] = Field(default=None, title="mqtt服务器端口号") 


class MqttClientOutSchema(MqttClientInSchema):
    type: Optional[str] = "MQTT"
